import {orderFind ,confirm ,payment ,complete, del ,cancel} from "../../api/order";
import utils from "../../utils/util"

Page({
    data: {
        orderId: null,
        orders:{}
    },
    onLoad(options) {
        this.data.orderId = options.orderId
        this.setData({
            orderId:this.data.orderId
        })
        this.getOrderFind()
    },
    getOrderFind(){
        orderFind(this.data.orderId).then(res =>{
            res.data.order.createDate = utils.datetimeFormat(res.data.order.createDate)
            if( res.data.order.seller.msg  == null){
                res.data.order.seller.msg  = ""
            }
            this.data.orders = res.data.order
            this.setData({
                orders:this.data.orders
            })
        })
    },
    confirmClick(){
        wx.showModal({
            title: '提示',
            content: '确认接单',
            success:(res)=> {
                if (res.confirm) {
                    let params = {
                        id:this.data.orderId
                    }
                    confirm(params).then(res=>{
                        this.getOrderFind()
                    })
                    this.getOrderFind()
                }
            }
        })
    },
    paymentClick(){
        wx.showModal({
            title: '提示',
            content: '确认付款',
            success:(res)=> {
                if (res.confirm) {
                    let params = {
                        id:this.data.orderId
                    }
                    payment(params).then(res=>{
                        this.getOrderFind()
                    })
                    this.getOrderFind()
                }
            }
        })
    },
    completeClick(){
        wx.showModal({
            title: '提示',
            content: '确认完成',
            success:(res)=> {
                if (res.confirm) {
                    let params = {
                        id:this.data.orderId
                    }
                    complete(params).then(res=>{
                        this.getOrderFind()
                        wx.navigateBack({
                            delta: 1
                        })
                    })
                    this.getOrderFind()
                }
            }
        })
    },
    closeOrder(){
        wx.showModal({
            title: '提示',
            content: '确认要关闭?',
            success:(res)=> {
                if (res.confirm) {
                    let params = {
                        id:this.data.orderId
                    }
                    cancel(params).then(res=>{
                        wx.navigateBack({
                            delta: 1
                        })
                    })
                }
            }
        })
    }
});